const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const UserSchema = new Schema({
  username: {type: String, require: true, unique: true,},
  password: {type: String, require: true, unique: false,},
  createTime: {type: Date, default: Date.now(),},
  updateTime: {type: Date, default: Date.now(),},
});

UserSchema.pre('save', function (next) {
  if (this.isNew) {
    this.createAt = this.updatedAt = Date.now();
  } else {
    this.updatedAt = Date.now();
  }
  next();
});

module.exports = mongoose.model('User', UserSchema);
